package com.himiotech.core.framework.config.gen;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * 读取代码生成相关配置
 *
 * @author ruoyi
 * @author wuwenbin
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "himio.gen")
public class GenConfig implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    /**
     * 作者
     */
    public String author;

    /**
     * 生成包路径
     */
    public String packageName;

    /**
     * 自动去除表前缀，默认是true
     */
    public boolean autoRemovePre;

    /**
     * 表前缀(类名不会包含表前缀)
     */
    public String tablePrefix;

    public static String getAuthorStatic() {
        return applicationContext.getBean(GenConfig.class).getAuthor();
    }

    public static String getPackageNameStatic() {
        return applicationContext.getBean(GenConfig.class).getPackageName();
    }

    public static boolean getAutoRemovePreStatic() {
        return applicationContext.getBean(GenConfig.class).isAutoRemovePre();
    }

    public static String getTablePrefixStatic() {
        return applicationContext.getBean(GenConfig.class).getTablePrefix();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        GenConfig.applicationContext = applicationContext;
    }
}
